package com.ruoyi.quartz.task;

import com.ruoyi.record.common.RecordConstant;
import com.ruoyi.record.domain.WordStudyStep;
import com.ruoyi.record.domain.WordStudyStepProgress;
import com.ruoyi.record.service.IWordStudyStepProgressService;
import com.ruoyi.record.service.IWordStudyStepService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;

/**
 * 定时任务调度
 */
@Slf4j
@Component("ryTask")
public class RyTask
{
    @Autowired
    private IWordStudyStepProgressService progressService;

    @Autowired
    private IWordStudyStepService stepService;

    /**
     * 筛选过期的任务数据
     * 添加过期标识
     * */
    public void selectOutdatedData(){
        WordStudyStepProgress progress = new WordStudyStepProgress();
        List<WordStudyStepProgress> progressList = progressService.selectStepProgressList(progress);
        log.info("ryTask-selectOutdatedData-查询到过期的任务数量:{}",progressList.size());
        if (progressList.isEmpty()){
            return;
        }
        for (WordStudyStepProgress progressItem : progressList) {
            progressItem.setActive(RecordConstant.ACTIVE_OUTDATED);
            progressService.updateWordStudyStepProgress(progressItem);
        }

        List<WordStudyStep> stepList = stepService.selectStepList(new WordStudyStep());
        log.info("ryTask-selectOutdatedData-查询到过期的主任务数量:{}",stepList.size());
        for (WordStudyStep step : stepList) {
            step.setActive(RecordConstant.ACTIVE_OUTDATED);
            stepService.updateWordStudyStep(step);
        }
    }

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }
}
